package com.mjfeed.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * @description 后台管理员
 * @author zhaominglei
 * @date 2014年9月20日
 */
@Entity
@Table(name = "feed_admin")
public class Admin extends BaseEntity implements Serializable {
	private static final long serialVersionUID = -6809429031501739156L;
	/** 姓名 */
	private String name;
	/** 用户名 */
    private String username;
    /** 密码 */
    private String password;
    /** 部门 */
    private String department;
    /** 邮箱 */
    private String email;
    /** 手机 */
    private String mobile;
    /** 登录ip */
    private String loginIp;
    /** 是否可用 */
    private Boolean isEnabled;
    /** 是否锁定 */
    private Boolean isLocked;
    /** 锁定日期 */
    private java.util.Date lockedDate;
    /** 登录日期 */
    private java.util.Date loginDate;
    /** 登录失败次数 */
    private Integer loginFailureCount;
    /** 角色 */
    private Set<Role> roles = new HashSet<Role>();
    /** 发货单 */
	private Set<Shipping> shippings = new HashSet<Shipping>();
	/** 管理日志 */
	private Set<AdminLog> adminLogs = new HashSet<AdminLog>();
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name="username", nullable=false, updatable=false, unique=true, length=100)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name="password", nullable=false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name="department", nullable=false)
	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	@Column(name="email", nullable=false)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	@Column(name="login_ip")
	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}
	
	@Column(name="is_enabled", columnDefinition="BIT", nullable=false)
	public Boolean getIsEnabled() {
		return isEnabled;
	}
	
	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	@Column(name="is_locked", columnDefinition="BIT", nullable=false)
	public Boolean getIsLocked() {
		return isLocked;
	}

	public void setIsLocked(Boolean isLocked) {
		this.isLocked = isLocked;
	}
	
	@Column(name="locked_date")
	public java.util.Date getLockedDate() {
		return lockedDate;
	}

	public void setLockedDate(java.util.Date lockedDate) {
		this.lockedDate = lockedDate;
	}
	
	@Column(name="login_date")
	public java.util.Date getLoginDate() {
		return loginDate;
	}

	public void setLoginDate(java.util.Date loginDate) {
		this.loginDate = loginDate;
	}

	@Column(name="login_failure_count")
	public Integer getLoginFailureCount() {
		return loginFailureCount;
	}

	public void setLoginFailureCount(Integer loginFailureCount) {
		this.loginFailureCount = loginFailureCount;
	}

	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "feed_admin_role", joinColumns={@JoinColumn(name="admin_id", updatable=false)}, inverseJoinColumns={@JoinColumn(name="role_id", updatable=false)})
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@OneToMany(mappedBy="operator", fetch=FetchType.LAZY, cascade = CascadeType.REMOVE)
	@OrderBy("createDate asc")
	public Set<Shipping> getShippings() {
		return shippings;
	}

	public void setShippings(Set<Shipping> shippings) {
		this.shippings = shippings;
	}

	@OneToMany(mappedBy="operator", fetch=FetchType.LAZY, cascade = CascadeType.REMOVE)
	@OrderBy("createDate asc")
	public Set<AdminLog> getAdminLogs() {
		return adminLogs;
	}

	public void setAdminLogs(Set<AdminLog> adminLogs) {
		this.adminLogs = adminLogs;
	}

}
